//
//  XDSegmentedView.m
//  HengHuaSupervision
//
//  Created by XD-XY on 3/21/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "XDSegmentedView.h"
#import "XDHeader.h"
#import "XDTools.h"

#define  btn_tag 65535
@implementation XDSegmentedView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        [self makeView];
    }
    return self;
}

-(void)makeView
{
    //左边选项卡
    self.leftButton = [UIButton initButton:CGRectMake(0, 0, mHomePage_Segmented_Left_Normal_Img.size.width,mHomePage_Segmented_Left_Normal_Img.size.height) btnNorImage:mHomePage_Segmented_Left_Normal_Img btnSelectBtn:mHomePage_Segmented_Left_Select_Img btnTitle:@"未贴" titleNorColor:mHomepagesegmented_Title_Normal_Color titleSelectColor:mHomepagesegmented_Title_Select_Color titleFont:mHomepagesegmented_text_Font];
    _leftButton.tag = btn_tag;
    _leftButton.enabled = YES;
    [_leftButton addTarget:self action:@selector(chooseBtnClick:) forControlEvents:UIControlEventTouchDown];
    
    //中间选项卡
    self.middleButton = [UIButton initButton:CGRectMake(width_x(_leftButton), 0, mHomePage_Segmented_Middle_Normal_Img.size.width, mHomePage_Segmented_Middle_Normal_Img.size.height) btnNorImage:mHomePage_Segmented_Middle_Normal_Img btnSelectBtn:mHomePage_Segmented_Middle_Select_Img btnTitle:@"全部" titleNorColor:mHomepagesegmented_Title_Normal_Color titleSelectColor:mHomepagesegmented_Title_Select_Color titleFont:mHomepagesegmented_text_Font];
    _middleButton.tag = btn_tag+1;
    _middleButton.enabled = NO;
    [_middleButton addTarget:self action:@selector(chooseBtnClick:) forControlEvents:UIControlEventTouchDown];
    
    //右边选项卡
    self.rightButton = [UIButton initButton:CGRectMake(width_x(_middleButton), 0,mHomePage_Segmented_Right_Normal_Img.size.width,mHomePage_Segmented_Right_Normal_Img.size.height) btnNorImage:mHomePage_Segmented_Right_Normal_Img btnSelectBtn:mHomePage_Segmented_Right_Select_Img btnTitle:@"已贴" titleNorColor:mHomepagesegmented_Title_Normal_Color titleSelectColor:mHomepagesegmented_Title_Select_Color titleFont:mHomepagesegmented_text_Font];
    _rightButton.tag = btn_tag+2;
    _rightButton.enabled = YES;
    [_rightButton addTarget:self action:@selector(chooseBtnClick:) forControlEvents:UIControlEventTouchDown];
    
    [self addSubview:_leftButton];
    [self addSubview:_middleButton];
    [self addSubview:_rightButton];
}


-(void)chooseBtnClick:(UIButton *)sender
{
    for (UIButton * button in [self subviews]){
        if ([button isKindOfClass:[UIButton class]]){
            button.enabled = button.tag==sender.tag?NO:YES;
        }
    }
    [_delegate changeSengmentIndex:(int)sender.tag -btn_tag];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/



@end
